#include <click/config.h>
#include <click/confparse.hh>
#include <click/error.hh>
#include "QosSwitch.hh"

CLICK_DECLS

bool QosSwitch::fSwitch;

QosSwitch::QosSwitch() {
	fSwitch = true;
}

QosSwitch::~QosSwitch() {
}

int QosSwitch::configure(Vector<String> &conf, ErrorHandler *errh) {
	if (cp_va_kparse(conf, this, errh, cpEnd) < 0) return -1;
	
	return 0;
}

int QosSwitch::doSwitch(const String &conf, Element *e, void * thunk, ErrorHandler * errh){
	QosSwitch* qosSwitch = (QosSwitch*) e;
	qosSwitch->fSwitch = !qosSwitch->fSwitch;
	click_chatter("Switch QoS to %i!", qosSwitch->fSwitch);
}

void QosSwitch::add_handlers() {
	add_write_handler("switch", &doSwitch, (void *)0);	
}

void QosSwitch::push(int value, Packet *p) {
	if (fSwitch) {
		output(0).push(p);
	} else {
		output(1).push(p);
	}

}

CLICK_ENDDECLS
EXPORT_ELEMENT(QosSwitch)
